import os
from time import sleep

from selenium.webdriver.common.by import By

from Base.base import Base


class AddQPage(Base):
    #定位商品管理
    goods_manager=(By.XPATH,'//span[text()="商场管理"]')
    #元素方法唯一时，可封装为函数
    def cmf(self):
        self.loc_wait_ele(self.goods_manager).click()

    # 定位商品管理
    general_problem = (By.XPATH, '//span[text()="通用问题"]')
    # 元素方法唯一时，可封装为函数
    def qpf(self):
        self.loc_wait_ele(self.general_problem).click()

    #添加按钮
    ab=(By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.filter-container > button:nth-child(3)")
    def add_p_b(self):
        self.loc_wait_ele(self.ab).click()

    #输入问题
    p_i=(By.CLASS_NAME,"el-input__inner")
    #p_i=(By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(1) > div > div > input")
    def inp(self,c):
        eles=self.loc_eles(self.p_i)
        ele=eles[3]
        #ele=self.loc_wait_ele(self.p_i)
        ele.send_keys(c)

    a_i = (By.CLASS_NAME, "el-textarea__inner")
    def aip(self, c):
        ele = self.loc_wait_ele(self.a_i)
        ele.send_keys(c)

    c_b=(By.XPATH,'//div[@class="dialog-footer"]/button[2]')
    def cbp(self):
        self.loc_wait_ele(self.c_b).click()


    dy=(By.XPATH,'//table[@class="el-table__body"]/tbody/tr[1]/td[2]/div')
    def gdc(self):
        return self.loc_wait_ele(self.dy).text


    def add_problem_bus(self,q,r):
        self.cmf()
        self.qpf()
        self.add_p_b()
        sleep(4)
        self.inp(q)
        sleep(1)
        self.aip(r)
        sleep(1)
        self.cbp()
        r=self.gdc()
        return r












